Mixed-Directional Text
Mixed-Directional Text
TextEdit now handles text with more than one script and direction. The
following sections explore how TextEdit treats mixed- directional text-the
combination of scripts with left-to-right and right-to-left directional
text-within a single line.
The following figure shows a line of Arabic text that contains some English
text. In this case, the primary line direction is right to left. The primary line
direction is the dominant line direction of the current script system and is
specified by the value of the system alignment global variable, TESysJust.
(TESysJust was referred to at one time as the system justification global
variable.) The value of TESysJust is -1 for a right-to-left primary line
direction and 0 for a left-to-right line direction. The default value of this
global variable is normally based on the system script. Your application can
use the SetSysJust procedure to change this value while drawing, but should
restore it afterward. See Macintosh Worldwide Development: Guide to System
Software for details.
A right-to-left primary line direction
TextEdit organizes text logically into a hierarchy of runs (consecutive
characters in memory with the same attributes) including style runs, script
runs, and direction runs. A style run is a sequence of text all in the same font,
style, size, and script. A script run is a sequence of text all in the same script.
A direction run is a sequence of text all in the same direction. The figure above
also shows three direction runs in the line.
Style runs (also called format runs ) are displayed in display order rather
than backing-store order for a right-to-left directional script. Display order
refers to the directional order in which the glyphs are displayed on the device,
which may be different from the way in which the characters they represent
are stored in the text buffer. Backing-store order is the sequence in which
characters are stored in memory.
Do not assume that display and backing-store orders are the same in any
script. For example, in left-to-right scripts, display and backing- store
orders are usually the same for most characters, whereas when right-to-left
scripts are present, the orders are often different. So for the characters that
appear in the figure above, the display order is as shown in the next figure.
The display order
The backing-store order of the characters in the figure before this last one is
as shown in the next figure.
Note: The visual appearance of some of the Arabic characters in the
previous figure and the next figure is different. To show characters
correctly in backing-store order, the indepen-dent forms of the characters
are used, but the display order of these same characters in the figure before
the last one shows the normal Arabic contextual forms. See
Worldwide Software Overview for more about contextual forms in
scripts.
The backing-store order
If the first character in backing-store order is Arabic and the line direction
is right to left, then this character is displayed on screen as the rightmost
character on the line. The converse is also true: if the first character in
backing-store order is Roman and the line direction is left to right, then this
character is displayed on screen as the leftmost character on the line.
The next figure shows that style runs on a line are grouped into script runs,
and the order of both style runs and script runs is determined by the direction
run of the script. Therefore, whenever your application calls any TextEdit
routine that requires line adjustment or re drawing, testing for mouse-down
events, or measuring of mixed- directional text (for example, TEDelete,
TEInsert, or TEDoText), TextEdit arranges the style runs so that they can be
displayed in display order-not in backing-store order. It uses the
Script Manager procedure GetFormatOrder to order the style runs for a
line.
Different levels of runs in a line of text
Read the following sections to find out how TextEdit
highlights characters in mixed- directional text
defines mouse-down event regions in mixed- directional text
displays dual carets to mark insertion points at direction boundaries
provides cursor movement across direction boundaries